<template>
	<!-- 商品列表 -->
	<view class="goods_list">
		<goods-list :prodect="prodect"></goods-list>
		<view class="over" v-if="flag">我也是有底线的！！！！！</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				pageindex: 1,
				prodect: [],
				flag:false
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		components: {
			"goodslist": goodsList
		},
		methods: {
			async getGoodsList() {
				const res = await this.$MyRequest({
					url: '/api/getgoods?pageindex=' + this.pageindex
				})
				// 拿出每一项
				this.prodect = [...this.prodect,...res.data.message]
				console.log(this.prodect)
				uni.stopPullDownRefresh()
				console.log(res)
			}
		},
		// 下拉触底
		onReachBottom(){
			if(this.prodect.length<this.pageindex*10) return this.flag =true
			this.pageindex++
			
			this.getGoodsList()
		},
		// 下拉刷新
		onPullDownRefresh(){
			this.prodect =[],
			this.flag =false
			this.getGoodsList()
			setTimeout(()=>{
				this.getGoodsList()
			},1000)
		}
	}
</script>

<style lang="scss">
.goods_list{
	background: gary;
}
.over{
	width: 100%;
	height: 50px;
	line-height: 50px;
	text-align: center;
	font-size: 28rpx;
}
</style>